package com.hqyj.dao;

import com.hqyj.pojo.ManagerUserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 关于userInfo的数据库操作
 */
@Mapper //这个接口是执行的mybatis的数据库操作
public interface ManagerUserInfoDao {

    //登录
    @Select("select * from userInfo where userName=#{userName} and userPwd=#{userPwd}")
    ManagerUserInfo login(ManagerUserInfo user);

    //验证用户名是否重名
    @Select("select count(*) from userInfo where userName=#{userName}")
    int valName(ManagerUserInfo user);

    //查询用户名是否存在,并且取出盐值
    @Select("select * from userInfo where userName=#{userName}")
    ManagerUserInfo selectByName(ManagerUserInfo user);

    //注册
    @Insert("insert into userInfo (userName,userPwd,salt) value (#{userName},#{userPwd},#{salt})")
    int zhuce(ManagerUserInfo user);

    //查询
    @Select("select * from userInfo ")
    List<ManagerUserInfo> select();

    //根据userid查询
    @Select("select * from userInfo where userId=#{userId}")
    ManagerUserInfo selectByUserId(ManagerUserInfo user);

    //修改
    @Update("update userInfo set userPwd=#{userPwd},userName=#{userName},userSex=#{userSex},userBir=#{userBir},userTel=#{userTel},userEmail=#{userEmail},userEdu=#{userEdu},userIdCard=#{userIdCard},userUnit=#{userUnit},userManager=#{userManager},userText=#{userText} where userId=#{userId}")
    int update(ManagerUserInfo user);

    //删除
    @Delete("delete from userInfo where userId=#{userId}")
    int del(ManagerUserInfo user);

    //新建
    @Insert("insert into userInfo (userPwd,userName,userSex,userBir,userTel,userEmail,userEdu,userIdCard,userUnit,userManager,userText,salt)" +
            "value(#{userPwd},#{userName},#{userSex},#{userBir},#{userTel},#{userEmail},#{userEdu},#{userIdCard},#{userUnit},#{userManager},#{userText},#{salt})")
    int xinjian(ManagerUserInfo user);

    //根据编号查询
    @Select("select * from userInfo where userId=#{userId}")
    List<ManagerUserInfo> findByUserId(ManagerUserInfo user);

    //根据用户名查询
    @Select("select * from userInfo where userName=#{userName}")
    List<ManagerUserInfo> findByUserName(ManagerUserInfo user);

    //修改密码
    @Update("update userInfo set userPwd=#{userPwd} where userId=#{userId}")
    int updatePwd(ManagerUserInfo user);

    //修改头像
    @Update("update userInfo set url=#{url} where userId=#{userId}")
    int updateHead(ManagerUserInfo user);


}
